# Maintainer: Václav Šmilauer <eu@doxos.eu>

_realname=highfive
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.10.1
pkgrel=1
pkgdesc='Modern header-only C++11 friendly interface for libhdf5 (mingw-w64)'
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
msys2_repository_url='https://github.com/BlueBrain/HighFive'
url='https://bluebrain.github.io/HighFive/'
license=('spdx:BSL-1.0')
depends=("${MINGW_PACKAGE_PREFIX}-hdf5")
makedepends=(
  "${MINGW_PACKAGE_PREFIX}-cc"
  "${MINGW_PACKAGE_PREFIX}-cmake"
  "${MINGW_PACKAGE_PREFIX}-ninja"
  "${MINGW_PACKAGE_PREFIX}-catch"
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-opencv"
  "${MINGW_PACKAGE_PREFIX}-eigen3"
)
optdepends=(
  "${MINGW_PACKAGE_PREFIX}-boost"
  "${MINGW_PACKAGE_PREFIX}-opencv"
  "${MINGW_PACKAGE_PREFIX}-eigen3"
)
source=("https://github.com/BlueBrain/HighFive/archive/v${pkgver}/${_realname}-${pkgver}.tar.gz")
sha256sums=('60d66ba1315730494470afaf402bb40300a39eb6ef3b9d67263335a236069cce')

build() {
  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("-DCMAKE_BUILD_TYPE=Release")
  else
    extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
  fi

  # HIGHFIVE_* options only affect tests (at package-build time),
  # not what is installed
  # (xtensor is not packaged, thus OFF)

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -GNinja \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    "{extra_config[@]}" \
    -DHIGHFIVE_USE_BOOST=ON \
    -DHIGHFIVE_USE_EIGEN=ON \
    -DHIGHFIVE_USE_XTENSOR=OFF \
    -DHIGHFIVE_USE_OPENCV=ON \
    -DHIGHFIVE_UNIT_TESTS=OFF \
    -DHIGHFIVE_PARALLEL_HDF5=OFF \
    -DHIGHFIVE_BUILD_DOCS=OFF \
    -DCMAKE_RUNTIME_OUTPUT_DIRECTORY="${srcdir}/build-${MSYSTEM}" \
    -DBoost_NO_BOOST_CMAKE=OFF \
    -S HighFive-${pkgver} \
    -B build-${MSYSTEM}

  ${MINGW_PREFIX}/bin/cmake --build build-${MSYSTEM}
}

check() {
  cd "${srcdir}"/build-${MSYSTEM}

  # run unit tests
  ${MINGW_PREFIX}/bin/ctest
}

package() {
  cd "${srcdir}"/build-${MSYSTEM}

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/cmake --install .

  install -Dm644 "${srcdir}"/HighFive-${pkgver}/LICENSE \
    -t "${pkgdir}"${MINGW_PREFIX}/share/licenses/${_realname}/
}
